
# class Person(object):
#
#     def __eq__(self, other):
#
#         return "查询条件 "
#
#
# if __name__ == '__main__':
#     p1 = Person()
#     p2 = Person
#     print(p1 == p2)


# import functools
#
# # 问题： 装饰器会改变被装饰的视图函数名称
# # 方案：@functools.wraps(视图函数名称)
#
#
# def get_user_info(view_func):
#     @functools.wraps(view_func)
#     def wrapper(*args, **kwargs):
#         pass
#         # 装饰功能
#         # 原有函数功能
#     return wrapper
#
# @get_user_info
# def index():
#     pass
#
# @get_user_info
# def news_detail():
#     pass
#
#
# if __name__ == '__main__':
#     print(index.__name__)
#     print(news_detail.__name__)

import datetime
import random

from info import db
from info.models import User
from manage import app


def add_test_users():
    users = []
    # 当前系统时间
    now = datetime.datetime.now()
    for num in range(0, 10000):
        try:
            user = User()
            user.nick_name = "%011d" % num
            user.mobile = "%011d" % num
            user.password_hash = "pbkdf2:sha256:50000$SgZPAbEj$a253b9220b7a916e03bf27119d401c48ff4a1c81d7e00644e0aaf6f3a8c55829"
            # 最后一次登录时间 2018-12-27  <--> 2019-01-27 过去一个月随机活跃时间
            #                  当前时间  -  随机秒数(2678400一个月的秒数)
            user.last_login = now - datetime.timedelta(seconds=random.randint(0, 2678400))
            users.append(user)
            print(user.mobile)
        except Exception as e:
            print(e)
    # 开启应用上下文
    with app.app_context():
        db.session.add_all(users)
        db.session.commit()

if __name__ == '__main__':
    add_test_users()